package com.payment.notify.api;

import com.jeeccm.modules.web.support.Result;
import com.jeeccm.modules.web.support.ResultEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springside.modules.web.MediaTypes;

import com.payment.common.dto.notify.SmsParamDto;
import com.payment.common.enums.notify.NotifyTypeEnum;
import com.payment.common.utils.number.NotifyUtil;
import com.payment.notify.message.Producer;


// Spring Restful MVC Controller的标识, 直接输出内容，不调用template引擎.
@RestController
public class AccountEndPoint {

	private static Logger logger = LoggerFactory.getLogger(AccountEndPoint.class);
	
	@Autowired
	private Producer producer; 

	/**
	 * 生产者调用接口
	 * @return
	 */
	@RequestMapping(value = "/api/sendMessage",produces = MediaTypes.JSON_UTF_8)
	public ResultEntity sendMessage() {
//		 GbNotifyRecord param = new GbNotifyRecord();
//		 param.setVersion((short)0);
//		 param.setNotifyTimes((short)0);
//		 param.setLimitNotifyTimes((short)5);
//		 param.setStatus((short)101);
//		 param.setUrl("http://www.baidu.com");
//		 param.setContent("测试发送");
//		 param.setCreateTime(new Date());
//		 param.setLastNotifyTime(new Date());
//		 param.setNotifyType((short)NotifyTypeEnum.SMS.getValue());
//		
		SmsParamDto smsDto = new SmsParamDto("13720895280","456789",NotifyTypeEnum.SMS.getValue());
		
		String message;
		message = NotifyUtil.formatSms(smsDto,"13720895280","456789");
		System.out.println("message=="+message);
		producer.sendMessage(message);
		ResultEntity entity = new ResultEntity.ResultBuilder(Result.SUCCESS)
				.data(message)
				.builder();
		return entity;
	}
	
}
